package com.ruitu.mall_98_seller.ui.order;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.ruitu.arad.base.BaseActivity;
import com.ruitu.arad.base.base_list.ListBaseAdapter;
import com.ruitu.arad.base.base_list.SuperViewHolder;
import com.ruitu.mall_98_seller.R;
import com.ruitu.mall_98_seller.dao.bean.Order;
import com.ruitu.mall_98_seller.dao.bean.OrderInfo;
import com.ruitu.mall_98_seller.mvp.model.OrderModel;
import com.ruitu.mall_98_seller.mvp.presenter.OrderPresenter;

import java.util.ArrayList;
import java.util.List;

// 第一版订单详情
public class OrderDetailActivity extends BaseActivity<OrderPresenter.OrderDetailP, OrderModel.OrderDetailM> {
    // 基本信息, 商品信息, 预售信息, 预订信息, 拼团信息, 收货信息,
    private RecyclerView rcv_base, rcv_pro, rcv_pre_sale, rcv_reserve, rcv_collage, rcv_address;

    private OrderDetailAdapter adapter1, adapter2, adapter3, adapter4, adapter5, adapter6;

    private List<OrderInfo> infoList1 = new ArrayList<>();
    private List<OrderInfo> infoList2 = new ArrayList<>();
    private List<OrderInfo> infoList3 = new ArrayList<>();
    private List<OrderInfo> infoList4 = new ArrayList<>();
    private List<OrderInfo> infoList5 = new ArrayList<>();
    private List<OrderInfo> infoList6 = new ArrayList<>();

    private RecyclerView rcv_list;// 订单详情信息列表

    private Order order;// 传过来的订单对象 (暂时只能使用id属性,因为消息页面跳过来的时候只有id属性)
    private Order orDetail;// 请求得到的订单详情对象

    @Override
    protected int getLayoutRes() {
        return R.layout.activity_order_detail;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        rcv_list = findViewById(R.id.rcv_list);
        rcv_base = findViewById(R.id.rcv_base);
        rcv_pro = findViewById(R.id.rcv_pro);
        rcv_pre_sale = findViewById(R.id.rcv_pre_sale);
        rcv_reserve = findViewById(R.id.rcv_reserve);
        rcv_collage = findViewById(R.id.rcv_collage);
        rcv_address = findViewById(R.id.rcv_address);

        setHeadTitle("订单详情");
        order = (Order) getIntent().getSerializableExtra("order");

        adapter1 = new OrderDetailAdapter(this);
        adapter2 = new OrderDetailAdapter(this);
        adapter3 = new OrderDetailAdapter(this);
        adapter4 = new OrderDetailAdapter(this);
        adapter5 = new OrderDetailAdapter(this);
        adapter6 = new OrderDetailAdapter(this);
        GridLayoutManager manager1 = new GridLayoutManager(this, 2);
        GridLayoutManager manager2 = new GridLayoutManager(this, 2);
        GridLayoutManager manager3 = new GridLayoutManager(this, 2);
        GridLayoutManager manager4 = new GridLayoutManager(this, 2);
        GridLayoutManager manager5 = new GridLayoutManager(this, 2);
        GridLayoutManager manager6 = new GridLayoutManager(this, 2);
//        LinearLayoutManager manager1 = new LinearLayoutManager(this);
//        LinearLayoutManager manager2 = new LinearLayoutManager(this);
//        LinearLayoutManager manager3 = new LinearLayoutManager(this);
//        LinearLayoutManager manager4 = new LinearLayoutManager(this);
//        LinearLayoutManager manager5 = new LinearLayoutManager(this);
//        LinearLayoutManager manager6 = new LinearLayoutManager(this);
        rcv_base.setLayoutManager(manager1);
        rcv_pro.setLayoutManager(manager2);
        rcv_pre_sale.setLayoutManager(manager3);
        rcv_reserve.setLayoutManager(manager4);
        rcv_collage.setLayoutManager(manager5);
        rcv_address.setLayoutManager(manager6);
        rcv_base.setAdapter(adapter1);
        rcv_pro.setAdapter(adapter2);
        rcv_pre_sale.setAdapter(adapter3);
        rcv_reserve.setAdapter(adapter4);
        rcv_collage.setAdapter(adapter5);
        rcv_address.setAdapter(adapter6);

        p.reqOrderDetail(order.getId());
        showProgress();
    }

    @Override
    public void onReqComplete(int code, boolean isOk, Object data) {
        if (code == 1) {
            orDetail = (Order) data;
            p.genOrderInfoList(orDetail, infoList1, infoList2, infoList3, infoList4, infoList5, infoList6);
            adapter1.setDataList(infoList1);
            adapter2.setDataList(infoList2);
            adapter3.setDataList(infoList3);
            adapter4.setDataList(infoList4);
            adapter5.setDataList(infoList5);
            adapter6.setDataList(infoList6);
        }
    }

    private class OrderDetailAdapter extends ListBaseAdapter<OrderInfo> {

        public OrderDetailAdapter(Context context) {
            super(context);
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_order_detail;
        }

        @Override
        public void onBindItemHolder(SuperViewHolder holder, int position) {
            TextView tv_name = holder.getView(R.id.tv_name);// 项目名称
            TextView tv_value = holder.getView(R.id.tv_value);// 项目的值

            OrderInfo info = mDataList.get(position);
            tv_name.setText(info.getName());
            tv_value.setText(info.getValue());
        }
    }
}
